from uuid import uuid4

from django.contrib.auth.models import PermissionsMixin, User, AbstractUser
from django.core import validators
from django.db import models
from django.core.mail import send_mail

from django.utils import timezone
from django.utils.translation import ugettext_lazy as _


class CustomUser(AbstractUser):
    first_name = ''
    last_name = ''
    email = models.EmailField(_('email address'), )

    department = models.ForeignKey("Department_Mode", blank=True, null=True, verbose_name="部门", related_name="users",
                                   on_delete=models.CASCADE)
    mobile = models.CharField('手机', max_length=30, blank=False,
                              validators=[validators.RegexValidator(r'^[0-9+()-]+$',
                                                                    ('请输入合法手机号码.'),
                                                                    '手机验证失败')])
    session_key = models.CharField(max_length=60, blank=True, null=True, verbose_name=u"session_key")
    user_key = models.TextField(blank=True, null=True, verbose_name="用户登录key")
    menu_status = models.BooleanField(default=False, verbose_name='用户菜单状态')
    user_active = models.BooleanField(verbose_name='设置密码状态', default=0)
    uuid = models.CharField(max_length=64, unique=True, default=uuid4)

    def get_short_name(self):
        return self.username

    def get_full_name(self):
        return self.username
